Skip to content

Parse OpenSSL versions without strings.SplitN - #72

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
charlie-morrison:openssl-parse-no-split
Dec 3, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
charlie-morrison:openssl-parse-no-split

Conversation

@charlie-morrison

Copy link
Copy Markdown
Contributor

Refs #31, the OpenSSL item.

parseOpenSSLVersion split the version with strings.SplitN(s, ".", 3), which allocates the parts slice on every call, twice per comparison. It now takes major and minor with nextDotPart, the same helper compareIntDot uses, and keeps the rest of the string as the third component. The rules after the split are unchanged: digit-only major and minor, and a third component that starts with digits, with the remainder as the patch letters or -alpha/-beta suffix.

The more results of nextDotPart are ignored on purpose. When the version has fewer than two dots, rest comes back empty and the existing "third component must start with a digit" check rejects it, which is what len(parts) != 3 did before. Mutation testing flagged explicit more checks as dead code, and the fuzz target below agrees.

go test -bench 'BenchmarkCompareWithScheme/OpenSSL' -benchmem, Go 1.26.7, linux/amd64, before and after run alternately (3 rounds of -count 3, so 9 runs each) on a slow, busy 2-core machine. Read the ratio, not the absolute numbers:

pair ns/op (median, min-max) B/op allocs/op
1.1.1w vs 1.1.1k main (76f6e73) 780 (730-1160) 96 2
this branch 397 (370-699) 0 0

The row is new in BenchmarkCompareWithScheme.

Coverage follows the IntDot change:

  • openssl_reference_test.go is a renamed copy of the old parseOpenSSLVersion.
  • TestParseOpenSSLVersionMatchesReference compares the parsed struct and the ok flag on the shared parity corpus plus OpenSSL forms: letter patches, -alpha/-beta/-pre, 3.x, missing, leading, doubled and extra dots, leading zeros, spaces and a non-ASCII digit.
  • TestParseOpenSSLVersionMatchesReferenceOnFixtures does the same for the conformance fixtures.
  • FuzzParseOpenSSLVersionMatchesReference ran 60 s here twice (370k and 191k execs), with no difference.
  • Two OpenSSL rows join TestEcosystemComparatorsDoNotAllocate, a letter patch and a prerelease. Both fail on main with 2 allocations.

Mutations, one at a time, in a separate worktree: no digit check on major, no digit check on minor, minor taken from the start of the string, major and minor swapped, the patch keeping its digits, and an empty third component accepted. All 6 turn a test red.

The 3.x path still goes through compareSemver, which this doesn't touch. go test ./... ok, golangci-lint run 0 issues, go vet ok, gofmt clean.

parseOpenSSLVersion now takes the major and minor components with
nextDotPart instead of splitting the version into a slice, so
compareOpenSSL no longer allocates.

refParseOpenSSLVersion keeps the old parser, and the new one is checked
against it on the parity corpus plus OpenSSL forms, the conformance
fixtures and a fuzz target. OpenSSL joins BenchmarkCompareWithScheme
and TestEcosystemComparatorsDoNotAllocate.

Refs git-pkgs#31

Co-authored-by: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 63ea10c4-7167-4f37-a3e4-209737719729
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@andrew
andrew merged commit ccec84f into git-pkgs:main Dec 3, 2026
3 checks passed
@charlie-morrison
charlie-morrison deleted the openssl-parse-no-split branch December 3, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants